package org.example;

public class Test1 {
    //leetcode 59螺旋矩阵II https://leetcode.cn/problems/spiral-matrix-ii/description/
    public int[][] generateMatrix(int n) {
        int[][] matrix = new int[n][n];
        int xl = 0, xr = n - 1, yt = 0, yb = n-1;
        int count = 1, x = 0, y = 0;
        while (count <= n * n) {
            while (count <= n * n && y <= xr) {
                matrix[x][y++] = count++;
            }
            y--;
            x++;
            xr--;
            while (count <= n * n && x < yb) {
                matrix[x++][y] = count++;
            }
            yb--;
            while (count <= n * n && y > xl) {
                matrix[x][y--] = count++;
            }
            xl++;
            while (count <= n * n && x > yt) {
                matrix[x--][y] = count++;
            }
            yt++;
            x++;
            y++;
        }
        return matrix;
    }

    public static void main(String[] args) {
        Test1 test1 = new Test1();
        test1.generateMatrix(1);
        System.out.println(666);
    }
}
